﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Microsoft.Reporting.WinForms;
using QldtSdh.BLL;
using QldtSdh.DAL.Models;
using QldtSdh.GUI.Common;
using QldtSdh.GUI.Utils;
using QldtSdh.Utils;
namespace QldtSdh.GUI.KhaoThi
{
    public partial class FormInLichThi : BaseForm
    {
        private string filePathTemp = Application.StartupPath + "\\{0}.doc";
        private int timeToWaitExport = 3000;
        WordUtil word = null;
        public FormInLichThi()
        {
            InitializeComponent();
        }

        private void FormInBangDiem_Load(object sender, EventArgs e)
        {

        }

        public void ShowOrPrint(string tenDotThi, HocKy hk, List<BLL.LichThi> lichThi, bool preview = true, bool printMultifile = false)
        {
            LichThiBindingSource.DataSource = lichThi;
            ReportParameter[] parameters = new ReportParameter[2];
            parameters[0] = new ReportParameter("rpTitleLichThi", string.Format("LỊCH THI HỌC KỲ - {0}", tenDotThi));
            if (hk != null)
                parameters[1] = new ReportParameter("rpSubTitleLichThi", string.Format("Học kỳ {0}", hk.TenHocKyDayDu));
            else
                parameters[1] = new ReportParameter("rpSubTitleLichThi", string.Format("Học kỳ {0}", "Không rõ"));
            System.Drawing.Printing.PageSettings pg = new System.Drawing.Printing.PageSettings();
            pg.Margins.Top = 30;
            pg.Margins.Bottom = 20;
            pg.Margins.Left = 20;
            pg.Margins.Right = 20;
            pg.Landscape = false;
            PaperSize size = new PaperSize();
            size.Width = 827;
            size.Height = 1169;
            pg.PaperSize = size;
            this.rvLichThi.SetPageSettings(pg);
            this.rvLichThi.LocalReport.SetParameters(parameters);

            this.rvLichThi.RefreshReport();
            rvLichThi.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
            rvLichThi.PrinterSettings.PrinterName = PrintUtil.GetDefaultPrinter();
            if (!preview)
            {
                //string fileName = string.Format(filePathTemp, lopHocPhan.MaLopHocPhanGUID.Replace(".", ""));
                LocalReport report = this.rvLichThi.LocalReport;
                //PrintUtil.Export(report, PrintUtil.WORDFORMAT, fileName);
                //Thread.Sleep(timeToWaitExport);
                //if (word == null)
                //    word = new WordUtil();
                //word.PrintDocument(fileName);
                PrintUtil.DoPrint(report,true);
            }
            else this.ShowDialog();
        }

    }
}
